Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




copy( ) FUNCTION


The copy( ) Function is used to copy the contents of a Set into a new Set.


Example :


x = {"Mohan", "Kriti", "Salim"}
y = x.copy()
print("The Copied Set is ",y)


Output :



  The Copied Set is {'Kriti', 'Salim', 'Mohan'}

So, in the above code we have created a 'List' and initialised to the variable 'x'.


x = {"Mohan", "Kriti", "Salim"}

java_Collections

Then we have used the 'copy( )' method that would create an exact copy of 'x'. And assign it to 'y'.


y = x.copy( )

java_Collections

And we get the below output,


The Copied Set is {'Kriti', 'Salim', 'Mohan'}

Note : Do not use the '=' operator to copy a Set to the other(i.e. If there are two Set 'x' and 'y'. Do not use y = x). Because in that case any changes made to the Set 'x' will be reflected in the copied Set 'y'.